package com.hb.trade.server.project.complaint.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hb.core.pojo.project.complaint.dto.ComplaintDTO;
import com.hb.core.pojo.project.complaint.entity.Complaint;
import com.hb.core.pojo.project.complaint.entity.ComplaintReply;
import com.hb.core.pojo.project.complaint.mapper.ComplaintMapper;
import com.hb.trade.server.project.complaint.service.ComplaintReplyService;
import com.hb.trade.server.project.complaint.service.ComplaintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 投诉异议Service实现类
 *
 * @author ljs
 * @date 2022-1-26 08:52:19
 */

@Service
public class ComplaintServiceImpl extends ServiceImpl<ComplaintMapper, Complaint> implements ComplaintService {

    @Autowired
    private ComplaintReplyService complaintReplyService;

    @Override
    public Page<ComplaintDTO> pageComplaint(ComplaintDTO complaintDTO) {
        Page<ComplaintDTO> complaintDTOPage = this.baseMapper.pageComplaint(complaintDTO.pages(), complaintDTO);
        return complaintDTOPage;
    }

    @Override
    public Page<ComplaintDTO> pageTenderComplaint(ComplaintDTO complaintDTO) {
        Page<ComplaintDTO> complaintDTOPage = this.baseMapper.pageTenderComplaint(complaintDTO.pages(), complaintDTO);
        return complaintDTOPage;
    }

    @Override
    public ComplaintDTO complaintDetail(ComplaintDTO complaintDTO) {
        // 查询投标人问题
        ComplaintDTO complaint = this.baseMapper.getComplaint(complaintDTO);
        // 查询投标人回复详情
        LambdaQueryWrapper<ComplaintReply> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(ComplaintReply::getComplaintId, complaintDTO.getId());
        List<ComplaintReply> complaintReply = complaintReplyService.list(queryWrapper);
        // 组装新的DTO对象
        if (null != complaintReply){
            complaint.setComplaintReplyList(complaintReply);
        }
        return complaint;

    }
}
